package com.aysafety.iotdataplatformweb.services.integrationWarning.impl;

import com.aysafety.core.common.DateUtils;
import com.aysafety.iotdataplatformweb.dao.MultiParameterIntegratedWarningDao;
import com.aysafety.iotdataplatformweb.services.integrationWarning.MultiParameterIntegratedWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MultiParameterIntegratedWarningServiceImpl implements MultiParameterIntegratedWarningService {

    @Autowired
    private MultiParameterIntegratedWarningDao multiParameterIntegratedWarningDao;

    @Override
    public Map<String, Object> comprehensiveWarning(String mineId, String startTime, String endTime) throws Throwable {
        Map<String, Object> resultMap = new HashMap<>();
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        //parram.put("tableId", "MULTIPARAMETERWARNING");
        //parram.put("pk", "\'" + mineId + ".:." + deviceId + "\'");
        //Map<String, Object> studyInfo = hydraulicsupportDao.queryHydraulicSupportWarningStudy(parram);

        //double R1 = Double.parseDouble(studyInfo.get("R1").toString());
        //double R2 = Double.parseDouble(studyInfo.get("R2").toString());
        //Map<String, Object> map = new HashMap<String, Object>();
        //map.put("R1", R1);//短预警
        //map.put("R2", R1 > R2 ? R1 : R2);//长预警
        //resultMap.put("R", R1);
        parram.put("tableId", mineId + "." + "MULTIPARAMETERWARNING");
        //parram.put("size", 1);
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        //List<Map<String, Object>> w = multiParameterIntegratedWarningDao.queryMultiParamsWarning(parram);
        // parram.put("startTime", "\'" + startTimeTimestamp + "\'");
        // parram.put("endTime", "\'" + endTimeTimestamp + "\'");
        //parram.remove("size");
        List<Map<String, Object>> wLists = multiParameterIntegratedWarningDao.queryMultiParamsWarning(parram);
        for (int i = 0; i < wLists.size(); i++) {
            long timestamp = (long) wLists.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            wLists.get(i).put("datetime", DateUtils.getTime(dateTime));

        }
        //resultMap.put("W", w.get(0).get("w"));
        resultMap.put("result", wLists);

        return resultMap;
    }
}
